﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using EntLibContrib.Query;

namespace EntLibContrib.Mapping.QuickStart.DomainObjects
{
	[SuperMapper(Name = "Owner Mapper", TypeColumnValue = "P")]
	public class PersonOwner : Owner
	{
		private Guid personId;
		private Person person;

		[Map()]
		public Guid PersonId
		{
			get { return personId; }
			set { personId = value; }
		}

		public Person Person
		{
			get
			{
				if (person == null)
				{
					if (personId != Guid.Empty)
					{
						IDictionary<string, object> parameters = new Dictionary<string, object>();
						parameters.Add("Id", personId);
						person = MapperFactory.CreateMapper("Person Mapper").ToDomainObject<Person>(QueryFactory.CreateQuery("Read Person By Id").ExecuteForRead(parameters));
					}
				}

				return person;
			}
		}

		public override string Name
		{
			get { return Person.Firstname + " " + Person.Surname; }
		}

		public PersonOwner()
		{ }
	}
}
